package com.ruoyi.project.system.info.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.system.info.domain.SocialInfo;
import com.ruoyi.project.system.info.service.ISocialInfoService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 社保信息Controller
 * 
 * @author xn
 * @date 2024-10-18
 */
@Controller
@RequestMapping("/system/info")
public class SocialInfoController extends BaseController
{
    private String prefix = "system/info";

    @Autowired
    private ISocialInfoService socialInfoService;

    @RequiresPermissions("system:info:view")
    @GetMapping()
    public String info()
    {
        return prefix + "/info";
    }

    /**
     * 查询社保信息列表
     */
    @RequiresPermissions("system:info:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(SocialInfo socialInfo)
    {
        startPage();
        List<SocialInfo> list = socialInfoService.selectSocialInfoList(socialInfo);
        return getDataTable(list);
    }

    /**
     * 导出社保信息列表
     */
    @RequiresPermissions("system:info:export")
    @Log(title = "社保信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(SocialInfo socialInfo)
    {
        List<SocialInfo> list = socialInfoService.selectSocialInfoList(socialInfo);
        ExcelUtil<SocialInfo> util = new ExcelUtil<SocialInfo>(SocialInfo.class);
        return util.exportExcel(list, "社保信息数据");
    }

    /**
     * 新增社保信息
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存社保信息
     */
    @RequiresPermissions("system:info:add")
    @Log(title = "社保信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(SocialInfo socialInfo)
    {
        return toAjax(socialInfoService.insertSocialInfo(socialInfo));
    }

    /**
     * 修改社保信息
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        SocialInfo socialInfo = socialInfoService.selectSocialInfoById(id);
        mmap.put("socialInfo", socialInfo);
        return prefix + "/edit";
    }

    /**
     * 查看社保信息
     */
    @GetMapping("/view/{id}")
    public String view(@PathVariable("id") Long id, ModelMap mmap)
    {
        SocialInfo socialInfo = socialInfoService.selectSocialInfoById(id);
        mmap.put("socialInfo", socialInfo);
        return prefix + "/view";
    }

    /**
     * 修改保存社保信息
     */
    @RequiresPermissions("system:info:edit")
    @Log(title = "社保信息", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(SocialInfo socialInfo)
    {
        return toAjax(socialInfoService.updateSocialInfo(socialInfo));
    }

    /**
     * 删除社保信息
     */
    @RequiresPermissions("system:info:remove")
    @Log(title = "社保信息", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(socialInfoService.deleteSocialInfoByIds(ids));
    }
}
